package com.bruce.thread;

import java.util.Hashtable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by bruce on 18/12/7 -- 15:20
 */
public class MultiThread {

    public static void main(String[] args) {
        // 创建一个可重用固定线程数的线程池
        ExecutorService pool = Executors.newFixedThreadPool(1);
        // 将线程放入池中进行执行
        for (int i = 1; i <= 1000; i++) {
            pool.execute(new MyThread(i));
        }
        // 关闭线程池
        pool.shutdown();
    }

    static class MyThread extends Thread {
        int num;
        public MyThread(int i) {
            this.num = i;
        }

        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "正在执行。。。" + this.getName());
        }
    }
}
